package dk.twu.analyzer.util;

public class VectorUtil {
    public static double[] flatToFirst(double[] input) {
        double[] translated = new double[input.length];
        double startVal = input[0];
        for (int i = 0; i < input.length; i++) {
            if (Double.isNaN(startVal) && !Double.isNaN(input[i])) {
                startVal = input[i];
            }
            translated[i] = input[i] / startVal;
        }
        return translated;
    }

    public static double[] flatToLast(double[] input) {
        double[] translated = new double[input.length];
        double lastVal = input[0];
        for (int i = 0; i < input.length; i++) {
            translated[i] = input[i] / lastVal;
            lastVal = input[i];
        }
        return translated;
    }

    public static double[] subtract(double[] from, double[] by) {
        if (from.length != by.length) {
            throw new IllegalArgumentException("Subtract from and by has different size.");
        }
        double[] result = new double[from.length];
        for (int i = 0; i < from.length; i++) {
            result[i] = from[i] - by[i];
        }
        return result;
    }
}
